#include<bits/stdc++.h>
using namespace std;
#define int long long

int a[10005];


void init(int n) {
	for (int i = 1; i <= n; i++)
		a[i] = i;
}


int find(int x) {
	if (a[x] != x)	a[x] = find(a[x]);
	return a[x];
}


void merge(int x, int y) {
	x = find(x);
	y = find(y);
	if (x != y)	a[x] = a[y];
}


signed main() {
	int n, m;
	cin >> n >> m;

	init(n);

	for (int i = 1; i <= m; i++) {
		int x, y, z;
		cin >> z >> x >> y;

		if (z == 1)
			merge(x, y);
		else {
			if (find(x) == find(y))
				cout << "Y";
			else
				cout << "N";
			cout << endl;
		}
	}

	return 0;
}
